package com.cat.math;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/four-divisors/
 * @create 2025/10/16 20:25
 * @since JDK17
 */

public class Solution15 {
    static int N = ((int) (1e5 + 10));
    static ArrayList<Integer>[] factors = new ArrayList[N];
    static {
        Arrays.setAll(factors, i -> new ArrayList<>());
        for (int i = 1; i < N; i++) {
            for (int j = i; j < N; j += i) {
                factors[j].add(i);
            }
        }
    }
    public int sumFourDivisors(int[] nums) {
        int ans = 0;
        for (int num : nums) {
            if (factors[num].size() == 4) {
                ans += factors[num].stream().reduce(0, (a, b) -> a + b);
            }
        }
        return ans;
    }
}
